<?php
namespace Home\Model;
use Think\Model;

class UserModel extends Model{

	protected $_validate = array(
	 array('username','require','请输入用户名！'),
	 array('password','require','请输入密码！'),
     array('username','','帐号名称已经存在！',0,'unique',1), // 在新增的时候验证name字段是否唯一
     array('repassword','password','确认密码不正确',0,'confirm'), // 验证确认密码是否和密码一致
   );

	//会员登录
	public function login($username,$password)
	{
		$where["username"] = $username;
		$where["password"] = md5(trim($password));
		$user = M("user")->where($where)->find();

		if($user){
			return $user;
		}else{
			return false;
		}
	}

	//获取所有会员信息
	public function getAllUserInfo()
	{
		$user = M("user")->select();
		return $user;
	}

	//获取指定会员信息
	public function getUserInfo($id)
	{
		$where['id'] = $id;
		$user = M("user")->where($where)->find();
		return $user;
	}

	//注册会员
	public function add($userinfo)
	{
		$userinfo["password"] = md5(trim($userinfo["password"]));
		$Model = M("user")->add($userinfo);
		if($Model){
			return true;
		}else{
			return false;
		}
	}
}